package com.goods.controller.business.converter;

import com.goods.common.model.business.ProductCategory;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class ProductCategoryConverter {

    /**
     *转成树节点
     * @param productCategoryList
     * @return
     */
    public static List<ProductCategoryTreeNodeVO> converterToCategoryVO(List<ProductCategory> productCategoryList){

        ArrayList<ProductCategoryTreeNodeVO> PCTN = new ArrayList<>();
        if(!CollectionUtils.isEmpty(productCategoryList)){
            for (ProductCategory productCategory : productCategoryList) {
                ProductCategoryTreeNodeVO productCategoryTreeNodeVO = new ProductCategoryTreeNodeVO();
                BeanUtils.copyProperties(productCategory,productCategoryTreeNodeVO);
                PCTN.add(productCategoryTreeNodeVO);
            }
        }
        return PCTN;
    }

    /**
     * 转成菜单和按钮
     * @param productCategoryList
     * @return
     */
    public static List<ProductCategoryVO> converterAllToCategoryVO(List<ProductCategory> productCategoryList){

        ArrayList<ProductCategoryVO> productCategoryVOS = new ArrayList<>();
        if(!CollectionUtils.isEmpty(productCategoryList)){
            productCategoryList.stream().forEach(productCategory -> {
                ProductCategoryVO productCategoryVO = new ProductCategoryVO();
                BeanUtils.copyProperties(productCategory,productCategoryVO);
                productCategoryVOS.add(productCategoryVO);
            });
        }
        return productCategoryVOS;
    }

    /**
     *转成菜单和按钮
     * @param productCategory
     * @return
     */
    public static ProductCategoryVO converterToProductCategoryVO(ProductCategory productCategory) {

        ProductCategoryVO productCategoryVO = new ProductCategoryVO();
        if (productCategory != null) {
            BeanUtils.copyProperties(productCategory, productCategoryVO);
        }
        return productCategoryVO;
    }
}
